package com.mr.example3.friend;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

/*
 * 1.输入数据：(好友	用户，用户)
 * 		（B	A,E,F）
 *
 * 2.输出数据：（用户-用户	好友）
 * 		(A-E	B)，(A-F	B),(E-F	B)
 */

public class Example3Mapper2 extends Mapper<Text, Text, Text, Text>{

	@Override
	protected void map(Text key, Text value, Mapper<Text, Text, Text, Text>.Context context)
			throws IOException, InterruptedException {

		String[] users = value.toString().split(",");

		for (int i = 0; i < users.length-1; i++) {

			for (int j = i+1; j < users.length; j++) {

				if(users[i].compareTo(users[j]) < 0) {

					context.write(new Text(users[i] + "-" + users[j]), key);

				}else {
					context.write(new Text(users[j] + "-" + users[i]), key);
				}


			}

		}

	}

}
